import Vue from "vue";
import App from "./App.vue";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import router from "./router";
import store from "./store/store";
import "@/mock/index";
import { postRequest } from "./api/api";
import { putRequest } from "./api/api";
import { deleteRequest } from "./api/api";
import { getRequest } from "./api/api";
import { initMenu } from "./api/menu";
import { uploadRequest } from "./api/api";
import echarts from 'echarts'

Vue.config.productionTip = false;
 
Vue.use(ElementUI );
 
Vue.prototype.postRequest = postRequest;
Vue.prototype.deleteRequest = deleteRequest;
Vue.prototype.getRequest = getRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.uploadRequest = uploadRequest;
Vue.prototype.$echarts = echarts;

router.beforeEach((to, from, next) => {
 
  if (window.sessionStorage.getItem("userInfo")) {
    //加载左侧菜单
    initMenu(router, store);
 
    next();
  } else {
    if (to.path == "/") {
      next();
    } else {
      next("/?redirect=" + to.path);
    }
  }
});

new Vue({
  render: (h) => h(App),
  router,
  store,
}).$mount("#app");
